import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

import '../../../data/models/bt_block.dart';
import '../../utils/bt_toast_utils.dart';
import '../models/bt_block_list_model.dart';

class BtBlockItemWidget extends StatelessWidget {
  const BtBlockItemWidget({
    super.key,
    required this.index,
    required this.item,
    required this.model,
  });

  final int index;

  final BtBlock item;

  final BtBlockListModel model;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(left: 20, right: 20),
      child: Container(
        padding: const EdgeInsets.only(top: 16, bottom: 16),
        decoration: const BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: Color(0xFFFFFFFF),
            ),
          ),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Container(
              decoration: BoxDecoration(
                gradient: const LinearGradient(
                  colors: [Color(0xFF14A7D5), Color(0xFF7F55F5)],
                ),
                borderRadius: BorderRadius.circular(34),
                border: Border.all(
                  width: 1,
                ),
              ),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(22),
                child: CachedNetworkImage(
                  width: 44,
                  height: 44,
                  fit: BoxFit.cover,
                  imageUrl: item.avatar,
                  placeholder: (context, url) => Image.asset(
                    'assets/images/bt_default_avatar.png',
                    width: 44,
                    height: 44,
                  ),
                  errorWidget: (context, url, error) => Image.asset(
                    'assets/images/bt_default_avatar.png',
                    width: 44,
                    height: 44,
                  ),
                ),
              ),
            ),
            const SizedBox(width: 10),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    item.nickName,
                    textAlign: TextAlign.center,
                    style: const TextStyle(fontSize: 14, color: Color(0xFF202020)),
                  ),
                  const SizedBox(height: 10),
                  Text(
                    item.registerCountry,
                    textAlign: TextAlign.center,
                    style: const TextStyle(
                      fontSize: 12,
                      color: Color(0x40000000),
                    ),
                  ),
                ],
              ),
            ),
            InkWell(
              child: Container(
                width: 71,
                height: 26,
                padding: const EdgeInsets.only(top: 3),
                decoration: BoxDecoration(
                  color: const Color(0xFF454545),
                  borderRadius: BorderRadius.circular(37),
                ),
                child: const Text(
                  'Unblock',
                  textAlign: TextAlign.center,
                  style: TextStyle(
                    fontSize: 12,
                    color: Color(0xFFFFFFFF),
                  ),
                ),
              ),
              onTap: () {
                model.removeBlock(item.broadcasterId, (success, msg) {
                  if (success) {
                    showToast(msg);
                  }
                });
              },
            )
          ],
        ),
      ),
    );
  }
}
